﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// BTypeManageBLL 的摘要说明
/// </summary>
public class BTypeManageBLL
{
    DataBase data = new DataBase();
    public BTypeManageBLL()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    #region 添加--图书类型信息
    /// <summary>
    /// 添加--图书类型信息
    /// </summary>
    /// <param name="btypemanage"></param>
    /// <returns></returns>
    public int AddBookType(BTypeManage btypemanage)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@typename",  SqlDbType.VarChar, 30, btypemanage.TypeName ),
            data.MakeInParam("@days",  SqlDbType.Int, 4,btypemanage.Days ),
            };
        return (data.RunProc("INSERT INTO tb_booktype (typename,days) VALUES(@typename,@days)", prams));
    }
    #endregion

    #region 修改--图书类型信息
    /// <summary>
    /// 修改--图书类型信息
    /// </summary>
    /// <param name="btypemanage"></param>
    /// <returns></returns>
    public int UpdateBookType(BTypeManage btypemanage)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.Int, 4, btypemanage.ID),
            data.MakeInParam("@typename",  SqlDbType.VarChar, 30, btypemanage.TypeName ),
            data.MakeInParam("@days",  SqlDbType.Int, 4,btypemanage.Days ),
            };
        return (data.RunProc("update tb_booktype set typename=@typename,days=@days where id=@id", prams));
    }
    #endregion

    #region 删除--图书类型信息
    /// <summary>
    /// 删除--图书类型信息
    /// </summary>
    /// <param name="btypemanage"></param>
    /// <returns></returns>
    public int DeleteBookType(BTypeManage btypemanage)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.Int, 4, btypemanage.ID),
            };
        return (data.RunProc("delete from tb_booktype where id=@id", prams));
    }
    #endregion

    #region 查询--图书类型信息
    /// <summary>
    /// 根据--类型名称--得到图书类型信息
    /// </summary>
    /// <param name="btypemanage"></param>
    /// <param name="tbName"></param>
    /// <returns></returns>
    public DataSet FindBTypeByName(BTypeManage btypemanage, string tbName)
    {
        SqlParameter[] prams = {
            data.MakeInParam("@typename",  SqlDbType.VarChar, 30, btypemanage.TypeName+"%"),
            };
        return (data.RunProcReturn("select * from tb_booktype where typename like @typename", prams, tbName));
    }
    /// <summary>
    /// 得到所有--图书类型信息
    /// </summary>
    /// <param name="tbName"></param>
    /// <returns></returns>
    public DataSet GetAllBType(string tbName)
    {
        return (data.RunProcReturn("select * from tb_booktype ORDER BY typename", tbName));
    }
    #endregion
}